<?php

class Tab_cats_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = 'set_tab_cats';
    }

    function newTabCat($added_by) {
        $data = $_POST;
        $data['added_by'] = $added_by;
        $data['deleted'] = 0;
        $data['last_modified'] = date("Y-m-d H:i:s");
        $this->db->insert($this->tableName, $data);
    }

    function delete($tid) {
        $where['tid'] = $tid;
        $data['deleted'] = 1;
        $data['last_modified'] = date("Y-m-d H:i:s");
        $this->db->where($where);
        $this->db->update($this->tableName, $data);
    }

    function getAll() {
        $this->db->select('tid,name');
        $where['deleted'] = 0;
        $this->db->where($where);
        $this->db->from($this->tableName);
        $query = $this->db->get();
        $result = array();
        foreach ($query->result_array() as $row) {
            $tid = $row['tid'];
//            unset($row['tid']);
            $row['links'] = "<a href='javascript:gotoUrl(\"" . base_url() . "index.php?/admin_settings/deleteTabCat/$tid\",
            \"Are you sure to delete this tab category?\")'>
            <img src='" . base_url() . "images/delete.png'
                 onmouseover='tooltip.show(\"Delete\");'
                onmouseout='tooltip.hide();' alt='DELETE'/></a>";
            $result[] = $row;
        }
        return $result;
    }

}